//
//  NSURL+ANDA_UrlString.m
//  ANDA_Club
//
//  Created by Lonely丶晏袁杰 on 2020/7/28.
//  Copyright © 2020 Lonely`yyj. All rights reserved.
//

#import "NSURL+ANDA_UrlString.h"

@implementation NSURL (ANDA_UrlString)
+ (void)load {
//   // 获取URLWithString:方法的地址
//   Method URLWithStringMethod = class_getClassMethod(self, @selector(URLWithString:));
//   // 获取BMW_URLWithString:方法的地址
//   Method BMW_URLWithStringMethod = class_getClassMethod(self, @selector(BMW_URLWithString:));
//   // 交换方法地址
//   method_exchangeImplementations(URLWithStringMethod, BMW_URLWithStringMethod);
   
}
+ (NSURL *)BMW_URLWithString:(NSString *)URLString {
   NSString *newURLString = [self isChinese:URLString];
   return [NSURL BMW_URLWithString:newURLString];
}
//处理特殊字符
+ (NSString *)isChinese:(NSString *)str {
//    NSString *returnString = @"";
//    NSArray *string = [str componentsSeparatedByString:@"?"];
//    if (string.count>0) {
//        for (int i = 0; i<string.count; i++) {
//            NSString *subString = string[i];
//            if (i == 0) {
//                returnString = [returnString stringByAppendingString:[subString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
//            }else{
//                returnString = [returnString stringByAppendingString:subString];
//            }
//        }
//    }else{
//        returnString = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
//    }
    return [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
//   NSString *newString = str;
//   //遍历字符串中的字符
//   for(int i=0; i< [str length];i++){
//       int a = [str characterAtIndex:i];
//       //汉字的处理
//       if( a > 0x4e00 && a < 0x9fff)
//       {
//           NSString *oldString = [str substringWithRange:NSMakeRange(i, 1)];
//           NSString *string = [oldString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
//           newString = [newString stringByReplacingOccurrencesOfString:oldString withString:string];
//       }
//       //空格处理
//       if ([newString containsString:@" "]) {
//           newString = [newString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
//
//       }
//     //如果需要处理其它特殊字符,在这里继续判断处理即可.
//   }
//   return newString;
}
@end
